// @include "../../../scripts/spket.js"

(function() {
	testAPIUsers = {
		name: function() {
			return "API Users Test";
		},
		setUp: function() {
			clear();
			init();
		},
		tearDown: function() {
			clear();
		},
		testAdd: function() {
			api.users.add({ name: 'xxx', desc: 'yyy' });

			var users = getUsers();
			Assert.assertEquals(3, users.length, 0);
			Assert.assertEquals("xxx", users[2].name);
			Assert.assertEquals("yyy", users[2].desc);
		},
		testUpdate: function() {
			dbo.users.update({ name: "user1", desc: 'XXX' });

			var users = getUsers();
			Assert.assertEquals(2, users.length, 0);
			Assert.assertEquals("user1", users[0].name);
			Assert.assertEquals("XXX", users[0].desc);
		},
		testRemove: function() {
			api.users.remove("user1");

			var users = getUsers();
			Assert.assertEquals(1, users.length, 0);
			Assert.assertEquals("user2", users[0].name);
			Assert.assertEquals("desc2", users[0].desc);
		}
	};

	function clear() {
		panda.db.get("users").drop();
	}

	function init() {
		var users = panda.db.get("users");
		users.ensureIndex({ name: 1 });
		users.insert({ name: "user1", desc: "desc1" });
		users.insert({ name: "user2", desc: "desc2" });
	}

	function getUsers() {
		var users = panda.db.get("users");
		return users.list().$sort({ name: 1 });
	}
}());
